﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class TestResults : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void _goButton_Click(object sender, EventArgs e)
    {
        try
        {
            TestResultsService.TestResultsServiceClient test_client =
                new TestResultsService.TestResultsServiceClient();

            EncryptionService.ServiceSoapClient encrypt_client =
                new EncryptionService.ServiceSoapClient("ServiceSoap");

            // encrypt the test and user id
            String user_id = encrypt_client.Encrypt("1");
            String test_id = encrypt_client.Encrypt("1");

            // call the test service
            TestResultsService.Test results = test_client.getTestResults(test_id, user_id);

            _displayResults(results);

        }
        catch (Exception ex)
        {
            String message =
                "An Exception occured in Test_TestResultsService. " + ex.Message;
            _results.Text = message;
        }
    }

    /// <summary>
    /// Show the results of the test in the results window
    /// </summary>
    /// <param name="results"></param>
    private void _displayResults(TestResultsService.Test test)
    {
        String message = "Test Results:\r\n";

        message += "Score: " + test.Score.ToString() + "\r\n";

        message += "-------------------------------------------\r\n";

        message += "Question Results:\r\n";

        foreach (TestResultsService.Question question in test.Questions)
        {
            message += question.QuestionText + "\r\n";
            for (int i = 0; i < question.Answers.Length; ++i)
            {
                message += (i + 1).ToString() + ". " + question.Answers[i] + "\r\n";
            }
            message += "Answer: " + question.CorrectIndex.ToString() + "\t";
            message += "Selected: " + question.SelectedIndex.ToString() + "\r\n\r\n";

        }

        _results.Text = message;
    }
}